package com.guofen.service.sjq.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.guofen.dao.SjqSolidliquidProduceInspectionMapper;
import com.guofen.pojo.SjqSolidliquidProduceElectricity;
import com.guofen.pojo.SjqSolidliquidProduceInspection;
import com.guofen.service.sjq.SjqSolidliquidProduceInspectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SjqSolidliquidProduceInspectionServiceImpl implements SjqSolidliquidProduceInspectionService {
    @Autowired
    SjqSolidliquidProduceInspectionMapper sjqSolidliquidProduceInspectionMapper;

    @Override
    public boolean add(String equipment_name,String is_normal,String remarks,String operator){
        Date now = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String date = dateFormat.format(now);

        SjqSolidliquidProduceInspection sjqSolidliquidProduceInspection = new SjqSolidliquidProduceInspection();
        sjqSolidliquidProduceInspection.setDate(date);
        sjqSolidliquidProduceInspection.setEquipmentName(equipment_name);
        sjqSolidliquidProduceInspection.setIsNormal(is_normal);
        sjqSolidliquidProduceInspection.setRemarks(remarks);
        sjqSolidliquidProduceInspection.setOperator(operator);

        int result = sjqSolidliquidProduceInspectionMapper.insert(sjqSolidliquidProduceInspection);
        if (result == 1)
            return true;
        else
            return false;
    }

    @Override
    public boolean update(String id,String inspector,String remarks){
        Date now = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String date = dateFormat.format(now);

        SjqSolidliquidProduceInspection sjqSolidliquidProduceInspection = new SjqSolidliquidProduceInspection();
        sjqSolidliquidProduceInspection.setId(Integer.parseInt(id));
        //sjqSolidliquidProduceInspection.setDate(date);//设置最新还是安旧的来
        sjqSolidliquidProduceInspection.setInspector(inspector);
        sjqSolidliquidProduceInspection.setRemarks(remarks);

        int result = sjqSolidliquidProduceInspectionMapper.updateByPrimaryKeySelective(sjqSolidliquidProduceInspection);
        if (result == 1)
            return true;
        else
            return false;
    }

    @Override
    public List<SjqSolidliquidProduceInspection> getlast_day(){
        return sjqSolidliquidProduceInspectionMapper.getlast();
    }

    @Override
    public Map<String, Object> get(int pageSize, int currentPage) {
        Map<String, Object> map = new HashMap<>();
        PageHelper.startPage(currentPage, pageSize);
        List<SjqSolidliquidProduceInspection> list = sjqSolidliquidProduceInspectionMapper.selectAll();
        PageInfo pageRecord = new PageInfo(list);
        long sum = pageRecord.getTotal();
        list = pageRecord.getList();
        map.put("records",list);
        map.put("sum",sum);
        return map;
    }

    @Override
    public Map<String, Object> getByTime(int pageSize, int currentPage, long startTime, long endTime) {
        Map<String, Object> map = new HashMap<>();
        PageHelper.startPage(currentPage, pageSize);
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String startDate = dateFormat.format(new Date(startTime));
        String endDate = dateFormat.format(new Date(endTime));
        List<SjqSolidliquidProduceInspection> list = sjqSolidliquidProduceInspectionMapper.selectByDate(startDate, endDate);
        PageInfo pageRecord = new PageInfo(list);
        long sum = pageRecord.getTotal();
        list = pageRecord.getList();
        map.put("records",list);
        map.put("sum",sum);
        return map;
    }

    @Override
    public int delete(int id) {
        return sjqSolidliquidProduceInspectionMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int update(SjqSolidliquidProduceInspection record) {
        return sjqSolidliquidProduceInspectionMapper.updateByPrimaryKeySelective(record);
    }


}
